package srjava.messages;

import java.io.IOException;
import java.io.StringReader;
import java.util.Iterator;
import java.util.LinkedList;

public class ElectedRet extends Message {
	int numberOfTasks;
	LinkedList<TaskInfo> taskInfoList;
	
	public ElectedRet() {
		this.msgType = MessageType.ELECTED_RET;
		this.numberOfTasks = 0;
		this.taskInfoList = new LinkedList<TaskInfo>();
	}

	public int getNumberOfTasks() {
		return numberOfTasks;
	}

	public void setNumberOfTasks(int numberOfTasks) {
		this.numberOfTasks = numberOfTasks;
	}

	public LinkedList<TaskInfo> getTaskInfoList() {
		return taskInfoList;
	}

	public void setTaskInfoList(LinkedList<TaskInfo> taskInfoList) {
		this.taskInfoList = taskInfoList;
	}

	public ElectedRet(int numberOfTasks, LinkedList<TaskInfo> taskInfoList) {
		this.msgType = MessageType.ELECTED_RET;
		this.numberOfTasks = numberOfTasks;
		this.taskInfoList = taskInfoList;
	}

	@Override
	public String serialize() {
		String pom = super.serialize() + numberOfTasks + " " + taskInfoList.size() + " ";
		Iterator<TaskInfo> it = taskInfoList.iterator();
		while (it.hasNext()) {
			pom += it.next().serialize();
		}
		return pom;
	}

	@Override
	public void deSerialize(StringReader s) throws IOException {
		numberOfTasks = IntString.parseInt(s);
		int size = IntString.parseInt(s);
		for(int i=0; i<size; i++)
		{
			TaskInfo pom = new TaskInfo();
			pom.deSerialize(s);
			taskInfoList.add(pom);
		}
	}
}
